# 键值对

dic = {
    'name': '小明',
    'age': 28,
    'sex': '男',
    "wife": {
        'name': '小红',
        'age':27,
        'sex': '女'
    },
    'children': [
        {
            'name': '小刚',
            'age': 5,
            'sex': '男'
        },
        {
            'name': '小A',
            'age': 3,
            'sex': '女'
        }
    ]
}

print(dic)
dic['children'][1]['age'] = dic['children'][1]['age']+1
print(dic)

val = dic['name']
print(val)

print(dic)

dic2 = {}
dic2['高度'] = 100
dic2['厚度'] = 400

print(dic2)
dic2['高度'] = 200
print(dic2)

# setdefault 已存在key时不生效
dic2.setdefault('宽度', 1360)
dic2.setdefault('高度', 1360)
dic2.setdefault('姓名', '李靖')
print(dic2)

dic2.pop('宽度')
print(dic2)
print(dic2.get('高度'))
print(dic2.get('长度'))

# name2 = input('请输入name:')
# print(name2)
# val2 = dic2.get(name2)
# print(val2)
#
# if val2 is None:
#     print('没有这个键')
# else:
#     print('有这个键')
#


for key in dic2:
    print(key, dic2[key])

print(dic2.keys())
print(list(dic2.keys()))

print(dic2.values())
print(list(dic2.values()))

print(dic2.items())
print(list(dic2.items()))

print('========================')
for item in dic2.items():
    # 将item中的第一个元素和第二个元素分别赋值给key和value
    key,value = item[0],item[1]
    # 打印key和value，之间用冒号分隔
    print(key, ':', value)

print('========================')
for item in dic2.items():
    key,value = item
    print(key, ':', value)

print('========================')
for key,value in dic2.items():
    print(key, ':', value)


a,b = (1,2) # 元组解包

print(a,b)

